Create *.exe with PyInstaller

Create Executable of Python Script using PyInstaller

In this short guide, you’ll see how create an executable from a Python script using PyInstaller.

Here are the full steps to accomplish this goal in Windows.

 

1.      Add Python to PATH

To start, you may want to add Python to Windows path.

An easy way to add Python to the path is by downloading a recent version of Python, and then checking the box to ‘Add Python to PATH’ at the beginning of the installation:

 

Finish the installation, and you should be good to go.

2.      pip install pyinstaller

Next, open the Windows “Command Prompt” and then type the following command to install the PyInstaller package:

 

Step 3: Save your Python Script

3.      C:\Users\Ron\Desktop\Test

Now save your Python script at your desired location.

For demonstration purposes, let’s say that the Python script is stored in the following folder:

C:\Users\Ron\Desktop\Test\Hello.py

Where Python script is called hello‘ and the file extension is ‘.py

4.      C:\Users\Ron>cd C:\Users\Ron\Desktop\Test

Now you’ll be able to create the executable of the Python script using PyInstaller.

Simply go to the Command Prompt, and then type:

cd followed by the location where your Python script is stored

Here is the command for our example:

cd \Users\Ron\Desktop\Test\

 

Press Enter (after you typed the location where the Python script is stored on your computer).

 

Then, refer to the following template to create the executable:

pyinstaller --onefile Hello.py

Since for our example, the pythonScriptName is hello‘ (and the file extension is .py), then the command to create the executable is:

pyinstaller --onefile Hello.py

5.      pyinstaller --onefile hello.py

6.      C:\Users\Ron\Desktop\Test\dist

The new executable will be located under the dist folder.

You’ll notice that few additional files were created at that location.

To find the executable file, open the dist folder. You’ll then see the executable file:

hello.exe

Double click on the file, and you should be able to launch your program (if you get an error message, you may need to install Visual C++ Redistributable).

Type the name of the new *.exe, hello.exe and press enter.

Hello World!

 

 

 

https://datatofish.com/executable-pyinstaller/